home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / fractal / fdesi313 / fdes308s / fdesmodi.c < prev    next >
Text File  |  1990-01-18  |  12KB  |  342 lines

  1. /*
  2.         Modify Menu
  3. */
  4. #include <stdio.h>                      /* standard stuff */
  5. #include <graphics.h>                   /* graphics */
  6. #include <dos.h>
  7. #include <string.h>
  8. #include "fdestria.h"
  9. #include "fdesign.h"
  10. #include "fdesequa.h"
  11. #include "fdesfile.h"
  12. #include "fdesmenu.h"
  13. #include "fdesmous.h"
  14. #include "fdesplot.h"
  15.  
  16.  
  17. void grat_on(void)            /* put graticules on screen */
  18. {
  19. int x,y;
  20.     for (x=0; x<maxx; x += (maxx/GRAT_X))
  21.     for (y=0; y<maxy; y += (maxy/GRAT_Y))
  22.     {
  23.         putpixel(x,y,WHITE);
  24.     }
  25. }
  26.  
  27. void grat_off(void)            /* remove graticules from screen */
  28. {
  29. int x,y;
  30.     for (x=0; x<maxx; x += (maxx/GRAT_X))
  31.     for (y=0; y<maxy; y += (maxy/GRAT_Y))
  32.     {
  33.         putpixel(x,y,BLACK);
  34.     }
  35. }
  36.  
  37. popmenu modifymenu = {
  38.     7 ,
  39.         "Scratch Everything", "Add Triangle", "Delete Triangle", "Adjust Triangle",
  40.         "Grat is On", "Re-Crop", "Main Menu"
  41.     };
  42.  
  43. popmenu modi_quit = {
  44.         2 ,
  45.         "Stay here and continue to modify", "Return to main menu"
  46.         };
  47.  
  48. void recrop(void)               /* re-crop triangles in modify menu screen */
  49. {
  50. int x1,y1,x2,y2;
  51. float top,left,right,bottom;
  52. float scalex,scaley;
  53. float offsetx,offsety;
  54.         /* &&& */
  55.         putmsg(0,0,"Input box for triangles",BLUE,WHITE);
  56.         box_new(&x1,&y1,&x2,&y2);
  57.         clrmsg();
  58.         if ((x1==x2) || (y1==y2)) return;
  59.         triangles_limits(&left,&top,&right,&bottom);
  60.         scalex = (x2-x1)/(right - left);
  61.         scaley = (y2-y1)/(bottom - top);
  62.         if (scalex > scaley) scalex = scaley;
  63.         else scaley = scalex;
  64.         offsetx = -((left+right)/2.0)*scalex + (x2+x1)/2.0;
  65.         offsety = -((bottom+top)/2.0)*scaley + (y2+y1)/2.0;
  66.         IFS_rescale(scalex,offsetx,scaley,offsety,0);
  67.         triangles_use_temp();
  68. }
  69.  
  70.  
  71. void modify_scr(void)
  72. {
  73. int i;
  74.         cleardevice();
  75.         grat_on();
  76.     if (triangle0_is) {
  77.         setcolor(LIGHTRED);
  78.         setlinestyle(DASHED_LINE,0,THICK_WIDTH);
  79.         triangle_show(&triangle0);
  80.     }
  81.     if (num_triangles) {
  82.         setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  83.         for (i = 0; i < num_triangles; i++)
  84.         {
  85.                         setcolor(colors[i%MAXCOLORS_]);
  86.             triangle_show(&triangles[i]);
  87.         }
  88.     }
  89. }
  90. /************************************************************************
  91.     Modify Menu Input
  92. ************************************************************************/
  93. void modify_input(void)
  94. {
  95. float a,b,c;            /* length of triangle side */
  96. int select,rcode,i,done,add_done;
  97. int tr_sel,refok;
  98. int corner;
  99. int save_row,save_col;
  100. mouse_state m;
  101.     modify_scr();
  102.         plot_type = 1;                 /* do a small plot while inputting */
  103.         IFS_changed = 1;
  104.         mouse_idle_job = doIFSrand;     /* do a small plot while inputting */
  105.         done = 0;
  106.     do {
  107.                 select = popup(0,0,&modifymenu,WHITE,BLUE);
  108.         switch (select) {
  109.         case 1:
  110.                         IFS_changed = 1;
  111.                         stpcpy(last_file,"No File");
  112.                         file_modified = 0;
  113.                         mouse_idle_job = mouse_idle;
  114.             refok = 0;
  115.             do {
  116.                 num_triangles = 0;
  117.                 triangle0_is = 0;
  118.                 modify_scr();
  119.                                 putmsg(0,0,"Input reference triangle (big)",BLUE,WHITE);
  120.                 setlinestyle(DASHED_LINE,0,THICK_WIDTH);
  121.                                 triangle_new(&triangle0,LIGHTRED);
  122.                 clrmsg();
  123.                                 a = pt_pt_distance(triangle0.row[0],triangle0.col[0],
  124.                                                    triangle0.row[1],triangle0.col[1]);
  125.                                 b = pt_pt_distance(triangle0.row[1],triangle0.col[1],
  126.                                                    triangle0.row[2],triangle0.col[2]);
  127.                                 c = pt_pt_distance(triangle0.row[2],triangle0.col[2],
  128.                                                    triangle0.row[0],triangle0.col[0]);
  129.                 if ((a!=0)&(b!=0)&(c!=0)) {
  130.                     refok = 1;
  131.                     triangle0_is = 1; }
  132.                 else {
  133.                     putmsg(10,100,
  134.                     "Reference Triangle must have non-zero area",
  135.                     WHITE,BLACK);
  136.                     mouse_click(&m);
  137.                     clrmsg();
  138.                 }
  139.             } while (!refok);
  140.             do {
  141.                 setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  142.                                 putmsg(0,0,"Input triangle or end with right button",
  143.                        GREEN,WHITE);
  144.                                 rcode = triangle_new(&triangles[num_triangles],
  145.                                         colors[num_triangles%MAXCOLORS_]);
  146.                 if (((rcode&0x01) != 0) &&
  147.                    (transform_affine(&triangles[num_triangles]) == 0))
  148.                 {
  149.                     putmsg(100,100,
  150.                     "Transform not Affine (a side is too long)",
  151.                     RED,WHITE);
  152.                     mouse_click(&m);
  153.                     clrmsg();
  154.                     clrmsg();
  155.                     modify_scr();
  156.                                         IFS_changed = 1;        /* only for clearing window */
  157.                 }
  158.                 else if ((rcode&0x01) != 0) {
  159.                     num_triangles++;
  160.                     if (num_triangles > 1) {
  161.                         IFS_changed = 1;
  162.                         mouse_idle_job = doIFSrand;
  163.                     }
  164.                     clrmsg();
  165.                 }
  166.                                 else {
  167.                                         clrmsg();
  168.                 }
  169.                         } while ((rcode&0x01) && (num_triangles < MAXFUNC));
  170.             break;
  171.         case 2:    /* add triangle */
  172.             add_done = 0;
  173.                         if (num_triangles < MAXFUNC)
  174.             {
  175.                         file_modified = 1;
  176.             do {
  177.                                 putmsg(0,0,"Add one triangle",BLUE,WHITE);
  178.                 setlinestyle(SOLID_LINE,0,NORM_WIDTH);
  179.                                 rcode = triangle_new(&triangles[num_triangles],
  180.                                         colors[num_triangles%MAXCOLORS_]);
  181.                 if (transform_affine(&triangles[num_triangles]) == 0)
  182.                 {
  183.                         putmsg(100,100,"Transform not Affine (a side is too long)",
  184.                         RED,WHITE);
  185.                         mouse_click(&m);
  186.                         clrmsg();
  187.                         clrmsg();
  188.                                                 IFS_changed = 1; /* to clear screen */
  189.                         modify_scr();
  190.                 }
  191.                 else {
  192.                     if ((rcode&0x01) != 0)
  193.                                         {
  194.                                                 num_triangles++;
  195.                                                 if (num_triangles > 1) {
  196.                                                         IFS_changed = 1;
  197.                                                         mouse_idle_job = doIFSrand;
  198.                                                 }
  199.                                         }
  200.                     add_done = 1;
  201.                     clrmsg();
  202.                                         IFS_changed = 1;
  203.                 }
  204.             } while (add_done == 0);
  205.             }
  206.             break;
  207.         case 3:
  208.                         putmsg(0,0,"Select triangle to delete",BLUE,WHITE);
  209.             mouse_click(&m);
  210.             clrmsg();
  211.             tr_sel = pt_closest_triangle(m.col,m.row);
  212. /*            gotoxy(1,13); printf("Selected %d",tr_sel);
  213. */            if (tr_sel == -1) {
  214.                 putmsg(50,100,"Use Scratch Everything to delete Reference Triangle ",
  215.                     WHITE,RED);
  216.                                 mouse_click(&m);
  217.                 clrmsg();
  218.                 break;
  219.             }
  220.             if (tr_sel < (num_triangles-1))
  221.             {
  222.                                 file_modified = 1;
  223.                 if (tr_sel != (num_triangles-1)) {
  224.                     for (i=tr_sel; i<(num_triangles-1); i++) {
  225.                                                 triangles[i].row[0] = triangles[i+1].row[0];
  226.                                                 triangles[i].col[0] = triangles[i+1].col[0];
  227.                                                 triangles[i].row[1] = triangles[i+1].row[1];
  228.                                                 triangles[i].col[1] = triangles[i+1].col[1];
  229.                                                 triangles[i].row[2] = triangles[i+1].row[2];
  230.                                                 triangles[i].col[2] = triangles[i+1].col[2];
  231.                     }
  232.                 }
  233.             }
  234.             num_triangles--;
  235.                         if (num_triangles > 1) {
  236.                 IFS_changed = 1;
  237.                 mouse_idle_job = doIFSrand;
  238.             }
  239.             else {
  240.                 mouse_idle_job = mouse_idle;
  241.             }
  242.                         IFS_changed = 1;
  243.             modify_scr();
  244.             break;
  245.                 case 4: /* adjust triangle */
  246.                         putmsg(0,0,"Select triangle to adjust",BLUE,WHITE);
  247.             mouse_click(&m);
  248.             clrmsg();
  249.             tr_sel = pt_closest_triangle(m.col,m.row);
  250.                         if (tr_sel == -1) {
  251.                                 putmsg(50,100,"Cannot Adjust Reference Triangle ",WHITE,RED);
  252.                 mouse_click(&m);
  253.                 clrmsg();
  254.                 break;
  255.             }
  256.                         else {
  257.                                 putmsg(0,0,"Select Corner to Move",GREEN,WHITE);
  258.                                 mouse_click(&m);
  259.                 corner = triangle_corner(&triangles[tr_sel],m.col,m.row);
  260.                                 clrmsg();
  261.                                 do {
  262.                                         putmsg(0,0,"Click left to move, Click right to end",BLUE,WHITE);
  263.                     rcode = mouse_click_grat(&m);
  264. /*                    rcode = mouse_click(&m); */
  265.                                         save_row = triangles[tr_sel].row[corner];
  266.                                         save_col = triangles[tr_sel].col[corner];
  267.                                         clrmsg();
  268.                                         if (rcode&0x01) {
  269.                                                 triangles[tr_sel].row[corner] = m.row;
  270.                                                 triangles[tr_sel].col[corner] = m.col;
  271.                                                 file_modified = 1;
  272.                         if (transform_affine(&triangles[tr_sel])) {
  273.                                                         IFS_changed = 1;
  274.                                                         modify_scr();
  275.                                                 }
  276.                                                 else {
  277.                                                         triangles[tr_sel].row[corner] = save_row;
  278.                                                         triangles[tr_sel].col[corner] = save_col;
  279.                                                         putmsg(100,100,"Not Affine",RED,WHITE);
  280.                                                         mouse_click(&m);
  281.                                                         clrmsg();
  282.                                                 }
  283.                                         }
  284.                                 } while (!(rcode&0x02));
  285.                         }
  286.                         break;
  287.                 case 5: /* toggle use_grat global variable */
  288.                         if (use_grat)
  289.                         {
  290.                                 use_grat = 0;
  291.                                 modifymenu.item[4] = "Grat is Off";
  292.                         }
  293.                         else
  294.                         {
  295.                                 use_grat = 1;
  296.                                 modifymenu.item[4] = "Grat is On";
  297.                         }
  298.                         break;
  299.                 case 6: /* re-crop */
  300.             recrop();
  301.             modify_scr();
  302.                         break;
  303.                 case 7: /* return/continue */
  304.             if (triangle0_is == 0) {
  305.                                 putmsg(100,100,"Error: No Triangles",RED,WHITE);
  306.                                 delay(1000);
  307.                 clrmsg();
  308.             } else if (num_triangles < 2) {
  309.                 putmsg(10,100,
  310.                                       "Error: At least two transformation triangles required",
  311.                       RED,WHITE);
  312.                                 delay(3000);
  313.                 clrmsg();
  314.             }
  315.             else {
  316.                 cleardevice();
  317.                                 plot_type = 0;
  318.                 mouse_idle_job = mouse_idle;
  319.                                 doIFSrand();
  320.                 done = 1;
  321.             }
  322.                         if (done == 0)
  323.                         {
  324.                                 select = popup(150,150,&modi_quit,WHITE,RED);
  325.                                 if (select == 2)
  326.                                 {
  327.                                         stpcpy(last_file,"No File");
  328.                                         file_modified = 0;
  329.                                         default_fractal();
  330.                                         cleardevice();
  331.                                         plot_type = 0;
  332.                                         mouse_idle_job = mouse_idle;
  333.                                         doIFSrand();
  334.                                         done = 1;
  335.                                 }
  336.                         }
  337.             break;
  338.         }
  339.     } while (!done);
  340. }
  341.  
  342.